package cn.jee.controller;

import cn.jee.entity.Teacher;
import cn.jee.repository.TeacherRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/teachers")
public class TeacherController {
    
    @Autowired
    private TeacherRepository teacherRepository;
    
    @GetMapping("/")
    public String index(Model model) {
        model.addAttribute("teachers", teacherRepository.findAll());
        return "index";
    }
    
    @GetMapping("/new")
    public String showCreateForm(Model model) {
        model.addAttribute("teacher", new Teacher());
        return "teacher/create";
    }
    
    @PostMapping("/")
    public String create(@ModelAttribute Teacher teacher) {
        teacherRepository.save(teacher);
        return "redirect:/teachers/";
    }
} 